package com.cjm.one.webmanager.controller.system;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.base.BaseDeleteMoreVo;
import com.cjm.one.model.system.dto.SysRoleDto;
import com.cjm.one.model.system.entity.SysRole;
import com.cjm.one.model.system.vo.RoleDetailVO;
import com.cjm.one.webmanager.service.system.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/manager/system/role")
@Tag(name = "1-系统管理-角色")
public class SysRoleController {
    @Resource
    private SysRoleService sysRoleService;
    /**
     * @description: 查询所有角色
     * @author: cjm 
     * @date: 2024/10/4 10:46
     * @param: []
     * @return: com.cjm.one.common.result.Result<java.util.List<com.cjm.one.model.system.entity.SysRole>>
     **/
    @GetMapping("/list/all")
    @Operation(description = "查询所有角色" )
    public Result<List<SysRole>> getAllSysRoleList() {
        return Result.ok(sysRoleService.getAllSysRoleList());
    }
    /**
     * @description: 条件分页查询角色列表
     * @author: cjm
     * @date: 2024/10/8 14:07
     * @param: [sysRoleDto]
     * @return: com.cjm.one.common.result.Result<com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.cjm.one.model.system.entity.SysRole>>
     **/
    @PostMapping("/list")
    @Operation(summary = "查询角色列表 分页")
    public Result<Page<SysRole>> page(@RequestBody SysRoleDto sysRoleDto){
        return Result.ok(sysRoleService.page(sysRoleDto));
    }
    @PutMapping
    @Operation(summary = "更新角色")
    public Result<Boolean> update(@RequestBody RoleDetailVO sysRole) {
        return Result.ok(sysRoleService.updateById(sysRole));
    }
    @PostMapping
    @Operation(summary = "新增角色")
    public Result<Boolean> addSysRole(@RequestBody RoleDetailVO sysRole) {
        return Result.ok(sysRoleService.save(sysRole));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除角色")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return Result.ok(sysRoleService.removeById(id));
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询角色")
    public Result<SysRole> getById(@PathVariable("id") Long id) {
        return Result.ok(sysRoleService.getById(id));
    }

    @DeleteMapping("/batch")
    @Operation(summary = "批量删除角色")
    public Result<BaseDeleteMoreVo> deleteBatchIds(@RequestBody List<Long> ids) {
        return Result.ok(sysRoleService.removeByIds(ids));
    }

    @PutMapping("/status")
    @Operation(summary = "更新角色状态")
    public Result<Boolean> updateStatus(@RequestBody SysRole sysRole) {
        return Result.ok(sysRoleService.updateStatus(sysRole));
    }

    @GetMapping("/{id}/detail")
    @Operation(summary = "根据id查询角色详情包含权限列表")
    Result<RoleDetailVO> getSysRoleDetail(@PathVariable("id") Long id){
        return Result.ok(sysRoleService.getSysRoleDetail(id));
    }

}
